<?php

	// +----------------------------------------------------------------------
	// | 图片文件管理
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\controller\file;


	use Qiniu\Auth as QuniuAuth;
	use Qiniu\Processing\PersistentFop;
	use Qiniu\Storage\UploadManager as QiniuUploadManager;
	use think\facade\Config;
	use yicmf\tools\HttpService;

	class Qiniu extends Common
	{


		public function index()
		{
			$setting = Config::get('upload_image');
			// 构建鉴权对象
			$auth = new QuniuAuth($setting['qiniu_access_key'], $setting['qiniu_secrect_key']);
			// 生成上传 Token
			$config = new \Qiniu\Config();

			$bucket = 'yicmf';
			//要转码的文件所在的空间和文件名。
			$key = 'uploads/attachment/201902/02/5c55795f605e0.mp4';
			//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
			$pipeline = 'yicmf';
			$force = false;
			//转码完成后通知到你的业务服务器。
			$notifyUrl = 'notify.php';
			//$config->useHTTPS=true;

			$pfop = new PersistentFop($auth, $config);

			//要进行转码的转码操作。 http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
//        $fops = "avthumb/mp4/s/640x360/vb/1.4m|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_640x360.mp4");
			$fops = 'avthumb/m3u8/noDomain/1/vb/500k/t/10';

			list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
			echo "\n====> pfop avthumb result: \n";
			if ($err != null) {
				dump($err);
			} else {
				echo "PersistentFop Id: $id\n";
			}

			//查询转码的进度和状态
			list($ret, $err) = $pfop->status($id);
			echo "\n====> pfop avthumb status: \n";
			if ($err != null) {
				dump($err);
			} else {
				dump($ret);
			}

			exit();
			$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
			list($fileInfo, $err) = $bucketManager->stat('yicmf', 'uploads/attachment/201902/01/5c53bd1d76ff0.mp3');
			dump($fileInfo);
			if ($err) {
				print_r($err);
			} else {
				print_r($fileInfo);
			}
		}

	}
